package com.example.bailin.giftsay.guide.adapter;

import android.support.v7.widget.RecyclerView;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.example.bailin.giftsay.R;
import com.example.bailin.giftsay.guide.PopupClick;
import com.example.bailin.giftsay.tool.MyApp;


/**
 * Created by bailin on 16/8/23.
 *
 * 精选页 popupwindow的适配器
 */
public class PopupAdapter extends RecyclerView.Adapter<PopupAdapter.PopupViewHolder> {
    private PopupClick popupClick;
    private int index;

    public void setIndex(int index) {
        this.index = index;
    }

    public void setPopupClick(PopupClick popupClick) {
        this.popupClick = popupClick;
    }

    private String[] strings = {"精选", "送女票", "海淘", "创意生活", "科技苑", "送爸妈",
            "送基友", "送闺蜜", "送同事", "送宝贝", "设计感", "文艺风", "奇葩搞怪", "萌萌哒", ""};

    @Override
    public PopupViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        View view = LayoutInflater.from(MyApp.getContext()).inflate(R.layout.item_poview, parent, false);
        return new PopupViewHolder(view);
    }

    @Override
    public void onBindViewHolder(PopupViewHolder holder, final int position) {
        if (index == position) {
            holder.tv.setTextColor(0xFFDE4C4C);
            holder.tvBack.setBackgroundColor(0XFFF43E5E);
        } else {
            holder.tv.setTextColor(0xFF7E7C7C);
            holder.tvBack.setBackground(null);
        }
        holder.tv.setText(strings[position]);
        holder.ll.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                if (position != 14) {
                    popupClick.itemOnClick(position);
                }
            }
        });
    }

    @Override
    public int getItemCount() {
        return strings.length;
    }

    public class PopupViewHolder extends RecyclerView.ViewHolder {
        TextView tv;
        LinearLayout ll;
        TextView tvBack;

        public PopupViewHolder(View itemView) {
            super(itemView);
            tv = (TextView) itemView.findViewById(R.id.tv_popup_item);
            ll = (LinearLayout) itemView.findViewById(R.id.ll_item_click);
            tvBack = (TextView) itemView.findViewById(R.id.tvBackground_id);
        }
    }
}
